package sg.edu.nus.iss.vmcs.machinery;

/*
 * Copyright 2011 ISS.
 * The contents contained in this document may not be reproduced in any
 * form or by any means, without the written permission of ISS, other
 * than for the purpose for which it has been supplied.
 *
 */

import java.awt.*;
import java.awt.event.*;

/**
 * DoorListener class creates the control object that monitors the door status
 * request (close door) when the controller uses the Machinery Simulator Panel.
 * It performs an action in response to the request. It implements the interface
 * ItemListener
 *
 * @version 1.0  07/12/2011
 * @author Team 7S - SE19
 */

public class DoorListener implements ItemListener {
	private MachineryController mctrl;

/**
 * The constructor for the DoorListener class. Creates an instance
 * of the object. 
 * @param mc
 * @see MachineryController
 */	
	public DoorListener(MachineryController mc) {
		mctrl = mc;
	}

/**
 * This method is implemented from the interface ItemListener. This method
 * is invoked on the state changed of the component CheckBox which represents
 * the door on the Machinery Simulator Panel.
 * @param e based on the item event triggered on item state changed
 * @see MachineryController
 */	
	
	public void itemStateChanged(ItemEvent e) {
		Checkbox cb;

		cb = (Checkbox) e.getSource();

		System.out.println("DoorListener:" + cb.getState());
		mctrl.setDoorState(cb.getState());
	}
}